package com.meitianhui.convenitenbuy.module.mine.presenter;

import com.google.gson.Gson;
import com.meitianhui.convenitenbuy.base.BaseArrayResponse;
import com.meitianhui.convenitenbuy.config.InfoProvider;
import com.meitianhui.convenitenbuy.http.ResponseObserver;
import com.meitianhui.convenitenbuy.module.mine.contract.SystemNotifyContract;
import com.meitianhui.convenitenbuy.module.mine.http.MineApiDataSource;
import com.meitianhui.convenitenbuy.module.mine.ui.activity.SystemNotifyActivity;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by amy on 2017/11/21.
 */

public class SystemNotifyPresenter implements SystemNotifyContract.Presenter {

    private SystemNotifyContract.View mView;
    private SystemNotifyActivity mContext;

    public SystemNotifyPresenter(SystemNotifyActivity activity, SystemNotifyActivity context) {
        this.mView = activity;
        this.mContext = context;
    }

    @Override
    public void attachView(Object view) {
    }

    @Override
    public void detachView() {
    }

    /**
     * 获取系统消息
     */
    @Override
    public void getSystemNotify() {
        Map<String, String> map = new HashMap<>();
        map.put("member_id", InfoProvider.getUserToken(mContext).getMember_id());

        MineApiDataSource.getInstance()
                .getSystemNotify(InfoProvider.getAppToken(mContext),
                        "member.appMsgNotifyQuery", new Gson().toJson(map))
                .subscribe(new ResponseObserver<BaseArrayResponse<String>>(mContext, true) {
                               @Override
                               public void onSuccess(BaseArrayResponse<String> response) {
                                   List<String> data = response.data;
                                   mView.getSystemNotifySuccess(data);
                               }

                               @Override
                               public void onFail(int code, String msg) {
                                   super.onFail(code, msg);
                                   mView.showError(msg);
                               }
                           }
                );
    }

}
